﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class QTHOCTAPDAO:IData<QTHOCTAP> 
 	{
		public QTHOCTAPDAO(String myconnecString) : base(myconnecString) { }

		protected override int InsertOnSubmit(ref QTHOCTAP item, int t) {
			 SqlParameter p = new SqlParameter(); 
			 if( t == 0)
				p.Direction = ParameterDirection.Output;
			 p.ParameterName = "@" + QTHOCTAP.c_ID;
			 p.Value = item.ID;
			 Object obj = item.ID; 
			int i = connec.ExecuteNonQuery("sp_QTHOCTAP", CommandType.StoredProcedure,p,ref obj,new SqlParameter("@flag", t),
				 new SqlParameter("@" + QTHOCTAP.c_MANV, item.MANV), new SqlParameter("@" + QTHOCTAP.c_MAGL, item.MAGL),
				 new SqlParameter("@" + QTHOCTAP.c_TGGL, item.TGGL), new SqlParameter("@" + QTHOCTAP.c_NVID, item.NVID),
				 new SqlParameter("@" + QTHOCTAP.c_GLID, item.GLID));
			if(t == 0)
				item.ID = Convert.ToInt32(obj);
			return i;
		}

		public override QTHOCTAP GetItem(IDataReader dr)
		{
			QTHOCTAP obj = new QTHOCTAP();
			obj.ID = Convert.ToInt32(dr[QTHOCTAP.c_ID]);
			obj.MANV = Convert.ToInt32(dr[QTHOCTAP.c_MANV]);
			obj.MAGL = Convert.ToString(dr[QTHOCTAP.c_MAGL]);
			obj.TGGL = Convert.ToString(dr[QTHOCTAP.c_TGGL]);
			obj.NVID = Convert.ToInt32(dr[QTHOCTAP.c_NVID]);
			obj.GLID = Convert.ToInt32(dr[QTHOCTAP.c_GLID]);
            obj.TENGL = Convert.ToString(dr[QTHOCTAP.c_TENGL]);
            obj.TENNV = Convert.ToString(dr[QTHOCTAP.c_TENNV]);
			return obj;
		}

		public override List<QTHOCTAP> GetAll()
		{
			return GetAll("sp_GetAllQTHOCTAP", CommandType.StoredProcedure);
		}

		public override QTHOCTAP GetItemById(object id)
		{
			return GetAll().SingleOrDefault(p => p.ID == Convert.ToInt32(id));
		}
		public override QTHOCTAP GetItemById(QTHOCTAP item){
			throw new NotImplementedException();
		}

	}

 }
